<?php $this->Html->script('jquery-1.7.2.min',false);?>
<?php $this->Html->script('jquery-ui-1.8.22.custom.min',false);?>
<?php echo $this->Html->css('jquery-ui-1.8.22.custom.css'); ?>
<script type="text/javascript">

	
	var itemCont = 2;
	
	function addFormFields()
	{
		var concept = '<tr><td><div class="input text"><input type="text" id="ServiceConcept" name="data[Item]['+itemCont+'][concept]"></div></td>';
		var price = '<td><div class="input text"><input type="text" id="ServicePrice" name="data[Item]['+itemCont+'][price]"></div></td>';
		var button = '<td><button type="button" onclick="javascript:delFormFields(\'data[Item]['+itemCont+'][price]\');">X</button></td></tr>'
		$('div table tr:last-child').after(concept+price+button);
		$('input[name="data[Item]['+itemCont+'][concept]"]').focus();
		itemCont++;
	}

	function delFormFields(name)
	{
		$('input[name="'+name+'"]').parent().parent().parent().remove();
	}
	
</script>
<div class="services form">
<?php echo $this->Form->create('Service'); ?>
	<fieldset>
		<legend><?php echo __('Agregar Servicio'); ?></legend>
	<?php
		
		
		echo $this->Form->input('numservicio',array('label'=>'Numero de Servicio', 'value'=>date('dmyHis'),'readonly'=>true));	
		echo $this->Form->input('descripcion',array('label'=>'Trabajo'));
		echo $this->Form->input('fecha',array('type'=>'text', 'id'=>'datePicker'));
		echo $this->Form->input('kilometraje');
		echo '<table><th>Concepto</th><th>Monto</th><tr><td>';
		echo $this->Form->input('concept',array('label'=>false,'name'=>'data[Item][1][concept]'));
		echo '</td><td>';
		echo $this->Form->input('price',array('label'=>false,'name'=>'data[Item][1][price]'));
		echo '</td><td><button class="btnClose" type="button" onclick="javascript:delFormFields(\'data[Item][1][price]\');">X</button>';
		echo '</td></tr></table>';
		echo $this->Form->hidden('car_id',array('value' => $idCar));
	?>
	<button class="btnClose"  type="button" onclick="javascript:addFormFields();">Agregar item</button>
	</fieldset>
<?php echo $this->Form->end(__('Guardar')); ?>
<script>
	$( "#datePicker" ).datepicker({dateFormat:"dd/mm/yy"});

	
</script>
</div>
<div class="actions">
	<h3><?php echo __('Actions'); ?></h3>
	<ul>

		<li><?php echo $this->Html->link(__('List Services'), array('action' => 'index')); ?></li>
		<li><?php echo $this->Html->link(__('List Cars'), array('controller' => 'cars', 'action' => 'index')); ?> </li>
		<li><?php echo $this->Html->link(__('New Car'), array('controller' => 'cars', 'action' => 'add')); ?> </li>
	</ul>
</div>
